<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ include file="../../common/layui.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<head>
    <title>可发起的流程</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
</head>
<body>

<!-- 可发起的流程  就是已经部署的流程  -->

<div class="section_mian">
    <!-- 列表页 -->
    <div class="larry-personal">
        <div class="layui-tab">

            <form class="layui-form">
                <table class="layui-table" id="layuitable" lay-filter="tableFilter"></table>
            </form>

        </div>
    </div>
</div>

<script type="text/html" id="toolbar">
    <a class="layui-btn btn_color_zise" lay-event="start" style="line-height: 25px;height: 25px;">发起流程</a>
</script>




<script type="text/javascript">
    function  reloadTable() {//刷新表格
        layui.table.reload('layuitable', {   where: {} });
    }
    layui.use(['laypage', 'layer', 'table', 'form', 'laydate'], function () {
        var laypage = layui.laypage
            , layer = layui.layer
            , table = layui.table
            , form = layui.form;
        var where = {};
        table.render({
            url: "flow/deploy/gird2",
            method: 'post', //方式
            elem: '#layuitable', //数据表格渲染到什么位置
            id: 'layuitable', //生成 Layui table 的标识 id 用于操作数据用
            where: where, //默认 参数
            cols: [[
                {checkbox: true},
                {field: "id", title: '部署ID', minWidth: 100},
                {field: "name", title: '名字', minWidth: 200},
                {field: "opt", title: '操作', toolbar: '#toolbar', width: 150}
            ]],
            done: function (res, curr, count) {
                $("[data-field='id']").css('display','none');//隐藏列,[data-field='state']
            },
            page: false

        });
        //监听工具条
        table.on('tool(tableFilter)', function (obj) { //注：tool是工具条事件名，tableFilter是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值
            var tr = obj.tr; //获得当前行 tr 的DOM对象
            var id = data.id;
            var name = data.name;
            if (layEvent === 'start') { //添加
                start( id ,name );
            }
        });

    });


    //发起一个流程
    function start(id,name) {
        //这里的会审，采用简单的流程，不给表单关联了
        if(name.indexOf("会审")!=-1){//是会审

            parent.layer.confirm('确定发起会审测试吗？', {
                btn : [ '确定', '取消' ]//按钮
            }, function(index) {

                var url = "flowhs/start?flowDepId="+id+"&flowName="+name;
                $.ajax({
                    url:url,
                    type:"POST",
                    data:{},
                    dataType:"json",
                    success:function(data){
                        parent.layer.msg('成功！', {icon: 1});
                    },
                    error:function(data){
                        parent.layer.msg('系统异常！', {icon: 5});
                    }
                });


            });


        }else{//普通流程

            parent.layer.open({
                type:2,
                btn: ['确定', '取消'],
                area: ['40%', '60%'],
                skin: 'layui-layer-lan',
                title: "发起"+name+"流程",
                shade: [0.5, '#393D49'],
                maxmin: true, //开启最大化最小化按钮
                content:"flow/open?flowDepId="+id+"&flowName="+name+"&load=add",
                yes:function(index,frameDom){
                    var openFrame = $(frameDom).find("iframe")[0].contentWindow; // 窗口
                    var res = openFrame.saveOrUpdate();
                    if(res==true){
                        parent.layer.close(index);
                    }else{
                        return false;
                    }
                }

            });


        }

    }
</script>

</body>
</html>
